package com.xu.cloud.auth.service.impl;

import com.xu.cloud.auth.component.TokenComponent;
import com.xu.cloud.auth.service.AccessTokenService;
import com.xu.cloud.common.auth.AuthContext;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.lang.Nullable;
import org.springframework.stereotype.Service;

/**
 * AccessToken Service Implement
 *
 * @author xuguan
 * @since 2025/2/23
 */
@Slf4j
@Service
public class AccessTokenServiceImpl implements AccessTokenService {

    @Autowired
    private TokenComponent tokenComponent;

    @Override
    public AuthContext resolveAndExtendAccessToken(@Nullable String accessToken) {
        log.info("解析并续期accessToken开始, accessToken={}", accessToken);
        final AuthContext authContext = tokenComponent.resolveAccessToken(accessToken, false);
        tokenComponent.extendAccessToken(accessToken);
        log.info("解析并续期accessToken结束, authContext={}", authContext);
        return authContext;
    }
}
